package com.raincat.toolsdemo.tools;

import java.util.HashMap;

/**
 * <pre>
 *     author : RainCat
 *     org    : Shenzhen JinYu Network Technology Co., Ltd.
 *     e-mail : nining377@gmail.com
 *     time   : 2020/11/24
 *     desc   : 杂物房
 *     version: 1.0
 * </pre>
 */

public class BaseInfo {
    public static CityInfo cityInfo;
    private static HashMap<String, CityInfo> cityInfoMap;

    public static final String refererUrl = "https://servicewechat.com/wx2c7f0f3c30d99445/62/page-frame.html";

    public static final String baseUrl = "https://cloud.cn2030.com";
    public static final String otherUrl = baseUrl + "/sc/wx/HandlerSubscribe.ashx";
    public static final String getUserInfo = baseUrl + "/sc/wx/HandlerSubscribe.ashx?act=User";
    public static final String getOrderStatus = baseUrl + "/sc/wx/HandlerSubscribe.ashx?act=GetOrderStatus";

    public static CityInfo getCityByName(String name) {
        if (cityInfoMap == null) {
            cityInfoMap = new HashMap<>();
            String cityInfoString = "450700,广西壮族自治区,钦州市,108.624175,21.967127;" +
                    "450300,广西壮族自治区,桂林市,110.299121,25.274215;" +
                    "451000,广西壮族自治区,百色市,106.616285,23.897742;" +
                    "450500,广西壮族自治区,北海市,109.119254,21.473343;" +
                    "450800,广西壮族自治区,贵港市,109.602146,23.0936;" +
                    "451200,广西壮族自治区,河池市,108.062105,24.695899;" +
                    "450200,广西壮族自治区,柳州市,109.411703,24.314617;" +
                    "450100,广西壮族自治区,南宁市,108.320004,22.82402;" +
                    "451300,广西壮族自治区,来宾市,109.229772,23.733766;" +
                    "451400,广西壮族自治区,崇左市,107.353926,22.404108;" +
                    "451100,广西壮族自治区,贺州市,111.552056,24.414141;" +
                    "450600,广西壮族自治区,防城港市,108.345478,21.614631;" +
                    "450400,广西壮族自治区,梧州市,111.297604,23.474803;" +
                    "450900,广西壮族自治区,玉林市,110.154393,22.63136;";
            String[] infos = cityInfoString.split(";");
            for (String info : infos) {
                String[] item = info.split(",");
                CityInfo cityInfo = new CityInfo();
                cityInfo.cityCode = item[0];
                cityInfo.provinceName = item[1];
                cityInfo.cityName = item[2];
                cityInfo.lat = Double.parseDouble(item[4]);
                cityInfo.lng = Double.parseDouble(item[3]);
                cityInfo.city = String.format(cityInfo.cityString, cityInfo.provinceName, cityInfo.cityName);
                cityInfoMap.put(cityInfo.cityName, cityInfo);
            }
        }
        return cityInfoMap.get(name);
    }

    public static class CityInfo {
        public String cityString = "[\"%s\",\"%s\",\"\"]";
        public String city = "";
        public String cityCode = "";
        public String cityName = "";
        public String provinceName = "";
        public double lat;
        public double lng;
    }
}
